{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9c854af7",
   "metadata": {},
   "source": [
    "## 尝试创建detect.py 并实现功能调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f46f7884",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "API_key = \"aZW8w-JCfLUxYnTwQQu_RKLAUduXKvTW\"\n",
    "API_secret = \"wmAcTGRDAkP1JB4zYe0H3Q15mn1UCMxC\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "64277204",
   "metadata": {},
   "outputs": [],
   "source": [
    "import detect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "76140ad2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module detect:\n",
      "\n",
      "NAME\n",
      "    detect\n",
      "\n",
      "FUNCTIONS\n",
      "    face_detect(API_key, API_secret, image_path)\n",
      "        该函数为调用face++ face_detect接口\n",
      "\n",
      "FILE\n",
      "    d:\\api_ai_ml\\week04\\detect.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(detect)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3271410a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648284422,0a12cfe6-3f7a-4e13-aaad-c575b884ef12',\n",
       " 'time_used': 171,\n",
       " 'faces': [{'face_token': '2f5c266f744feb0a2d2bdc03e5c155b4',\n",
       "   'face_rectangle': {'top': 340, 'left': 275, 'width': 334, 'height': 334}}],\n",
       " 'image_id': 'DCi4/BRGvLk6ltyr2iG6uQ==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "detect.face_detect(API_key,API_secret,'bjt.jpg')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5fbaa06a",
   "metadata": {},
   "source": [
    "## 尝试创建analyze.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "efce534e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# A-1 人脸分析中必选的一项包括face_tokens,先使用detect检测分析\n",
    "face_01 = detect.face_detect(API_key,API_secret,'bjt.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "511d0bfe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'c2f5b0fa0f3f54adc90d3b6eada5517c'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A-2 调取face_tokens\n",
    "face_tokens = face_01['faces'][0]['face_token']\n",
    "face_tokens"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1cf42021",
   "metadata": {},
   "outputs": [],
   "source": [
    "import analyze"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "64891375",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module analyze:\n",
      "\n",
      "NAME\n",
      "    analyze\n",
      "\n",
      "FUNCTIONS\n",
      "    face_analyze(API_key, API_secret, face_tokens, landmark=1, attributes=None, face_rectangle=None, beauty_score_min=0, beauty_score_max=100)\n",
      "        该函数为调用face++ face_analyze接口\n",
      "\n",
      "FILE\n",
      "    d:\\api_ai_ml\\week04\\analyze.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(analyze)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "a5eb6637",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 84,\n",
       " 'request_id': '1648284783,7ea959fc-25f9-466d-a2c0-378321cfdecf',\n",
       " 'faces': [{'landmark': {'mouth_upper_lip_left_contour2': {'y': 575, 'x': 445},\n",
       "    'mouth_upper_lip_top': {'y': 557, 'x': 480},\n",
       "    'mouth_upper_lip_left_contour1': {'y': 559, 'x': 465},\n",
       "    'left_eye_upper_left_quarter': {'y': 430, 'x': 322},\n",
       "    'left_eyebrow_lower_middle': {'y': 407, 'x': 320},\n",
       "    'mouth_upper_lip_left_contour3': {'y': 582, 'x': 458},\n",
       "    'right_eye_top': {'y': 363, 'x': 478},\n",
       "    'left_eye_bottom': {'y': 441, 'x': 345},\n",
       "    'right_eyebrow_lower_left_quarter': {'y': 347, 'x': 463},\n",
       "    'right_eye_pupil': {'y': 375, 'x': 479},\n",
       "    'mouth_lower_lip_right_contour1': {'y': 563, 'x': 509},\n",
       "    'mouth_lower_lip_right_contour3': {'y': 587, 'x': 515},\n",
       "    'mouth_lower_lip_right_contour2': {'y': 569, 'x': 525},\n",
       "    'contour_chin': {'y': 655, 'x': 518},\n",
       "    'contour_left9': {'y': 665, 'x': 475},\n",
       "    'left_eye_lower_right_quarter': {'y': 434, 'x': 361},\n",
       "    'mouth_lower_lip_top': {'y': 577, 'x': 487},\n",
       "    'right_eyebrow_upper_middle': {'y': 317, 'x': 478},\n",
       "    'left_eyebrow_left_corner': {'y': 427, 'x': 265},\n",
       "    'right_eye_bottom': {'y': 384, 'x': 490},\n",
       "    'contour_left7': {'y': 647, 'x': 398},\n",
       "    'contour_left6': {'y': 629, 'x': 364},\n",
       "    'contour_left5': {'y': 605, 'x': 333},\n",
       "    'contour_left4': {'y': 575, 'x': 309},\n",
       "    'contour_left3': {'y': 543, 'x': 287},\n",
       "    'contour_left2': {'y': 510, 'x': 267},\n",
       "    'contour_left1': {'y': 475, 'x': 251},\n",
       "    'left_eye_lower_left_quarter': {'y': 444, 'x': 327},\n",
       "    'contour_right1': {'y': 350, 'x': 560},\n",
       "    'contour_right3': {'y': 421, 'x': 578},\n",
       "    'contour_right2': {'y': 385, 'x': 571},\n",
       "    'mouth_left_corner': {'y': 593, 'x': 428},\n",
       "    'contour_right4': {'y': 457, 'x': 582},\n",
       "    'contour_right7': {'y': 562, 'x': 574},\n",
       "    'right_eyebrow_left_corner': {'y': 357, 'x': 438},\n",
       "    'nose_right': {'y': 490, 'x': 502},\n",
       "    'nose_tip': {'y': 494, 'x': 458},\n",
       "    'contour_right5': {'y': 492, 'x': 584},\n",
       "    'nose_contour_lower_middle': {'y': 524, 'x': 468},\n",
       "    'left_eyebrow_lower_left_quarter': {'y': 418, 'x': 292},\n",
       "    'mouth_lower_lip_left_contour3': {'y': 607, 'x': 471},\n",
       "    'right_eye_right_corner': {'y': 363, 'x': 514},\n",
       "    'right_eye_lower_right_quarter': {'y': 374, 'x': 504},\n",
       "    'mouth_upper_lip_right_contour2': {'y': 546, 'x': 512},\n",
       "    'right_eyebrow_lower_right_quarter': {'y': 325, 'x': 510},\n",
       "    'left_eye_left_corner': {'y': 445, 'x': 312},\n",
       "    'mouth_right_corner': {'y': 549, 'x': 530},\n",
       "    'mouth_upper_lip_right_contour3': {'y': 561, 'x': 508},\n",
       "    'right_eye_lower_left_quarter': {'y': 390, 'x': 474},\n",
       "    'left_eyebrow_right_corner': {'y': 385, 'x': 378},\n",
       "    'left_eyebrow_lower_right_quarter': {'y': 398, 'x': 349},\n",
       "    'right_eye_center': {'y': 376, 'x': 485},\n",
       "    'nose_left': {'y': 526, 'x': 414},\n",
       "    'mouth_lower_lip_left_contour1': {'y': 585, 'x': 458},\n",
       "    'left_eye_upper_right_quarter': {'y': 419, 'x': 359},\n",
       "    'right_eyebrow_lower_middle': {'y': 335, 'x': 487},\n",
       "    'left_eye_top': {'y': 420, 'x': 339},\n",
       "    'left_eye_center': {'y': 433, 'x': 343},\n",
       "    'contour_left8': {'y': 660, 'x': 435},\n",
       "    'contour_right9': {'y': 630, 'x': 549},\n",
       "    'right_eye_left_corner': {'y': 394, 'x': 458},\n",
       "    'mouth_lower_lip_bottom': {'y': 601, 'x': 496},\n",
       "    'left_eyebrow_upper_left_quarter': {'y': 402, 'x': 285},\n",
       "    'left_eye_pupil': {'y': 428, 'x': 343},\n",
       "    'right_eyebrow_upper_left_quarter': {'y': 333, 'x': 454},\n",
       "    'contour_right8': {'y': 597, 'x': 565},\n",
       "    'right_eyebrow_right_corner': {'y': 313, 'x': 531},\n",
       "    'right_eye_upper_left_quarter': {'y': 375, 'x': 464},\n",
       "    'left_eyebrow_upper_middle': {'y': 388, 'x': 314},\n",
       "    'right_eyebrow_upper_right_quarter': {'y': 308, 'x': 505},\n",
       "    'nose_contour_left1': {'y': 422, 'x': 397},\n",
       "    'nose_contour_left2': {'y': 495, 'x': 415},\n",
       "    'mouth_upper_lip_right_contour1': {'y': 548, 'x': 492},\n",
       "    'nose_contour_right1': {'y': 403, 'x': 445},\n",
       "    'nose_contour_right2': {'y': 467, 'x': 483},\n",
       "    'mouth_lower_lip_left_contour2': {'y': 603, 'x': 448},\n",
       "    'contour_right6': {'y': 528, 'x': 581},\n",
       "    'nose_contour_right3': {'y': 507, 'x': 486},\n",
       "    'nose_contour_left3': {'y': 527, 'x': 441},\n",
       "    'left_eye_right_corner': {'y': 427, 'x': 377},\n",
       "    'left_eyebrow_upper_right_quarter': {'y': 382, 'x': 346},\n",
       "    'right_eye_upper_right_quarter': {'y': 359, 'x': 497},\n",
       "    'mouth_upper_lip_bottom': {'y': 572, 'x': 486}},\n",
       "   'face_rectangle': {'width': 334, 'top': 340, 'left': 275, 'height': 334},\n",
       "   'face_token': 'c2f5b0fa0f3f54adc90d3b6eada5517c'}]}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "analyze.face_analyze(API_key,API_secret,face_tokens)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b33f37ea",
   "metadata": {},
   "source": [
    "## 尝试创建campare.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "db95e40e",
   "metadata": {},
   "outputs": [],
   "source": [
    "face_01 = detect.face_detect(API_key,API_secret,'bjt.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "892f3c2b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'0f87fcd789f7589824a384cc534939aa'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_token1 = face_01['faces'][0]['face_token']\n",
    "face_token1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "eed921d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "face_02 = detect.face_detect(API_key,API_secret,'bjt1.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "d5e3dcb3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'b66d55329af851f4b0182638d3492c3b'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_token2 = face_02['faces'][0]['face_token']\n",
    "face_token2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "00350961",
   "metadata": {},
   "outputs": [],
   "source": [
    "import compare"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "06c36099",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module compare:\n",
      "\n",
      "NAME\n",
      "    compare\n",
      "\n",
      "FUNCTIONS\n",
      "    face_compare(API_key, API_secret, face_token1, face_token2, face_rectangle1, face_rectangle2)\n",
      "        该函数为调用face++ face_compare接口\n",
      "\n",
      "FILE\n",
      "    d:\\api_ai_ml\\week04\\compare.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(compare)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "df9ceb52",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "face_compare() missing 2 required positional arguments: 'face_rectangle1' and 'face_rectangle2'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-34-f604c21bd11f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mcompare\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mface_compare\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mAPI_key\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mAPI_secret\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mface_token1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mface_token2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: face_compare() missing 2 required positional arguments: 'face_rectangle1' and 'face_rectangle2'"
     ]
    }
   ],
   "source": [
    "compare.face_compare(API_key,API_secret,face_token1,face_token2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfa115a5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
